﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Microsoft.TeamFoundation.WorkItemTracking.Client;

namespace Outlook.WorkItems.Extension.Controls
{
    public partial class RelatedWorkItemsForm : Form
    {
        public RelatedWorkItemsForm()
        {
            InitializeComponent();
        }

        public RelatedWorkItemsForm(IEnumerable<WorkItem> workItems)
            : this()
        {
            foreach (var item in workItems)
            {
                var lvi = new ListViewItem(item.Id.ToString());
                lvi.SubItems.Add(item.Type.Name);
                lvi.SubItems.Add(item.Title);
                lvi.SubItems.Add(item.State);
                lvi.Tag = item;
                listView1.Items.Add(lvi);
            }

        }

        private void listView1_DoubleClick(object sender, EventArgs e)
        {
            if (listView1.SelectedItems == null || listView1.SelectedItems.Count != 1)
                return;

            var wi = listView1.SelectedItems[0].Tag as WorkItem;
            
            if (wi == null) 
                return;

            using (var frm = new WorkItemForm(wi.Store, wi, true))
            {
                frm.ShowDialog(this);
            }
        }
    }
}
